from flask import Blueprint, render_template, request
from MovieLand.models import Movie

movie_route = Blueprint('movie_route', __name__, url_prefix='/movie')

@movie_route.route('/') # /moive/
def movie_index():
    res_query = request.args.get('page', 1, type=int)
    pagination = Movie.query.paginate(res_query, per_page=12) # 1 limit(12) 1:12
    list_view = pagination.items
    return render_template('movielist.html', movies=list_view, pagination=pagination)


@movie_route.route('/desc/<int:movie_id>') # /movie/desc/12 2
def movie_desc(movie_id):
    movie = Movie.query.get_or_404(movie_id)
    print(movie)
    return render_template('moviedesc.html', movie=movie)
